from BigDataWeb.algorithm import Algorithm
import os
import BigDataWeb.config as config


class HtmlDataVisualization(Algorithm):
    html_dest_path = ""
    html_template_name = ""
    html_template_path = ""
    html_items = {}
    html_text = ""

    def __init__(self):
        Algorithm.__init__(self)
        self.will_create_field_desc_chart = False
        self.html_dest_path = os.path.join(self.work_folder_path, "source_code_初始.html")
    
    def prepareHtmlItems(self):
        self.html_items = {}
    
    def generateHtmlFile(self):
        self.prepareHtmlItems()
        with open(os.path.join(config.sample_folder_path, self.html_template_name), encoding="UTF-8") as f1:
            self.html_text = f1.read()
            for key in self.html_items:
                self.html_text = self.html_text.replace(str(key), str(self.html_items[key]))
        
        with open(self.html_dest_path, "wt", encoding="UTF-8") as f2:
            f2.write(self.html_text)
